package com.sky.controller.admin;

import com.sky.annotation.AutoFillTime;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "菜品接口")
@RestController
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     * @param dto
     * @return
     */
    @AutoFillTime
    @ApiOperation("新增菜品")
    @PostMapping
    public Result addDish(@RequestBody DishDTO dto){
        return dishService.addDish(dto);
    }

    /**
     * 条件分页查询
     * @param dto
     * @return
     */
    @AutoFillTime
    @ApiOperation("条件分页查询")
    @GetMapping("/page")
    public Result<PageResult> queryByPage(DishPageQueryDTO dto) {
        return dishService.queryByPage(dto);
    }

    /**
     * 批量删除菜品
     * @param ids
     * @return
     */
    @AutoFillTime
    @ApiOperation("批量删除菜品")
    @DeleteMapping
    public Result deleteByIds(@RequestParam("ids") List<Long> ids){
        return dishService.deleteByIds(ids);
    }

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @AutoFillTime
    @ApiOperation("根据id查询菜品")
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id){
        return dishService.selectById(id);
    }

    /**
     * 修改菜品信息
     * @param dto
     * @return
     */
    @AutoFillTime
    @ApiOperation("修改菜品信息")
    @PutMapping
    public Result updateDish(@RequestBody DishDTO dto){
        return dishService.updateDish(dto);
    }


    /**
     * 根据分类id菜品
     * @param id
     * @return
     */
    @AutoFillTime
    @ApiOperation("根据分类id查询菜品")
    @GetMapping("list")
    public Result queryDishByCategoryId(@RequestParam(value = "categoryId") Long id){
        return dishService.queryDishByCategoryId(id);
    }

    /**
     * 菜品起售停售
     * @param status
     * @param id
     * @return
     */
    @AutoFillTime
    @ApiOperation("菜品起售停售")
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status,@RequestParam("id")Long id){
        return dishService.updateStatus(status,id);
    }
}
